home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / FILEOPEN.C < prev    next >
Text File  |  1992-05-14  |  3KB  |  69 lines

  1. /****************************************************************************************/
  2. /*    FileOpenProc                                                                        */
  3. /****************************************************************************************/
  4.  
  5. #include "MyHeaders.h"
  6.  
  7. int FileOpenProc ()
  8. {
  9.     int            FORetCode = 0;
  10.     SFTypeList    workTypeList;
  11.     Rect        dlogRect;
  12.     int            rectHeight, rectWidth;
  13.     int            newH, newV;
  14.     int            itemHit;                                /* return from modal dialog    */
  15.     
  16.     
  17.     myDlogPtr = GetNewDialog (getDlgID, NIL, (WindowPtr) -1);    /* get the dialog    */
  18.  
  19.     dlogRect = (*myDlogPtr).portRect;                    /* position dlog on desktop    */
  20.     rectHeight = dlogRect.bottom - dlogRect.top;        
  21.     rectWidth = dlogRect.right - dlogRect.left;
  22.     newH = (screenBits.bounds.right - rectWidth) * .50;    /* centered    horizonally        */
  23.     newH += 2;                                            /* jive it in                */
  24.     if (newH < 10)                                        /* (not less than 10)        */
  25.         newH = 10;
  26.     newV = ((screenBits.bounds.bottom - 30                /* vertical position        */
  27.              - rectHeight)* (.33)) + 30;                /*   one-third down            */
  28.     if (newV < 30)                                        /* (not less than 30)        */
  29.         newV = 30;
  30.  
  31.     if (appIndex <= appCount)                            /* if Finder has selection    */
  32.         {
  33.         GetAppFiles (appIndex, &appTheFile);            /* get the info from Finder    */
  34.         workReply.good = TRUE;                            /* transfer to work area    */
  35.         workReply.vRefNum = appTheFile.vRefNum;            /*    ditto                    */
  36.         workReply.fType = appTheFile.fType;                /*    ditto                    */
  37.         workReply.version = appTheFile.versNum;            /*    ditto                    */
  38.         workReply.fName[0] = appTheFile.fName[0];        /*    ditto                    */
  39.         strncpy ((char *) &workReply.fName[1],            /*    ditto                    */
  40.                 (char *) &appTheFile.fName[1],
  41.                 appTheFile.fName[0]); 
  42.         }
  43.     else                                                /* otherwise                */
  44.                                                         /* get info from SF dialog    */
  45.         {
  46.         workTypeList[0] = (long) 'TEXT';                /* set up to four types        */
  47.         workTypeList[1] = (long) 'ttro';                /* set up to four types        */
  48.         SetPt (&workPoint, newH,newV);                    /* upper left corner        */
  49.         SFGetFile (workPoint, NIL, NIL, 2, workTypeList, NIL, &workReply);    
  50.         if (workReply.good == FALSE)                    /* if cancel                */
  51.             {
  52.             FORetCode = 1;                                /* set bad ret code            */
  53.             goto ENDING;                                /* get out                    */
  54.             }
  55.         }
  56.         
  57.     workRC = FSOpen (&workReply.fName,                    /* open the file            */
  58.             workReply.vRefNum, &workPathRefNum);
  59.     if (workRC != noErr)
  60.         {
  61.         ParamText (&workReply.fName,"","","");            /* set text as file name    */
  62.         PlaceAlert (134);                                /* position the alert        */
  63.         StopAlert (134, NIL);                            /* show the alert            */
  64.         FORetCode = 1;                                    /* set bad ret code            */
  65.         }
  66.     
  67. ENDING:
  68.     return    FORetCode;
  69. }